#ifndef CODE_COMPLETER_H
#define CODE_COMPLETER_H

#include <QObject>
#include <QStringList>
#include <QSet>
#include <QMap>

class CodeEditor;

class CodeCompleter : public QObject {
    Q_OBJECT
    
public:
    explicit CodeCompleter(CodeEditor *editor);
    
    void updateCompletionModel(const QString &code);
    QStringList getCompletions(const QString &prefix) const;
    
    void setLanguage(const QString &lang);
    
private:
    void extractKeywords(const QString &code);
    void extractFunctions(const QString &code);
    void extractVariables(const QString &code);
    
    CodeEditor *editor;
    QString currentLanguage;
    
    // 语言特定的关键字
    QMap<QString, QSet<QString>> languageKeywords;
    
    // 从代码中提取的标识符
    QSet<QString> variables;
    QSet<QString> functions;
    
    void initLanguageKeywords();
};

#endif // CODE_COMPLETER_H